package com.minsu.service.impl;

import java.util.Random;

public class OrderNoGenerator {
    private static final Random RANDOM = new Random();
    private static final int TOTAL_LENGTH = 12;
    private static final int LETTER_PART_LENGTH = 2;
    private static final int NUMBER_PART_LENGTH = 10;

    /**
     * 生成12位生产单号（格式：2位大写字母 + 10位数字）
     * @return 随机生产单号（如 "AB1234567890"）
     */
    public static String generateProductionOrderNo() throws Exception{
        // 生成2位大写字母
        StringBuilder letterPart = new StringBuilder();
        for (int i = 0; i < LETTER_PART_LENGTH; i++) {
            // 生成'A'-'Z'的随机字母
            char randomLetter = (char) (RANDOM.nextInt(26) + 'A');
            letterPart.append(randomLetter);
        }

        /// 生成 10 位随机数字（0-9999999999）
        long randomNumber = Math.abs(RANDOM.nextLong()); // 取绝对值确保非负
        String numberPart = String.format("%0" + NUMBER_PART_LENGTH + "d", randomNumber % (long) Math.pow(10, NUMBER_PART_LENGTH));


        // 拼接两部分
        return letterPart.toString() + numberPart;
    }
}
